package cn.icare.cms.controller;

import cn.icare.cms.ItemService;
import cn.icare.cms.PromotionService;
import cn.icare.cms.feignclients.ADClient;
import cn.icare.cms.model.vo.rest.RespMsgVO;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping(value = "/rest/promotion")
@Api(tags = "REST促销")
public class PromotionController extends BaseController {
    @Autowired
    private PromotionService promotionService;
    @Autowired
    private ItemService itemService;
    private final String FALL_STRING = "请求失败,服务繁忙!";


    /**
     * 查询所有有效促销列表
     *
     * @return
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询当前所有有效促销列表", notes = "查询当前所有有效促销列表")
    public ResponseEntity<RespMsgVO> getAll() {
        return super.getRespOk(this.promotionService.getMiniEffectiveList());
    }

    /**
     * 查询所有有效促销列表
     *
     * @return
     */
    @GetMapping("/item/{id}")
    @ApiOperation(value = "查询分页查询某个促销商品列表", notes = "查询分页查询某个促销商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "promId", value = "促销Id", required = true, paramType = "query", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "name", value = "商品名称", required = false, paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, defaultValue = "1", paramType = "query", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = true, defaultValue = "20", paramType = "query", dataTypeClass = Integer.class)
    })

    public ResponseEntity<RespMsgVO> getPromItem(Integer promId, String name, Integer pageNum, Integer pageSize) {
        return super.getRespOk(this.itemService.getMiniPromList(promId,name,pageNum,pageSize));
    }


    //#region fallback methods
    //#endregion

}
